/// @tags:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

const int maxn = 5e5 + 3, maxk = 5e2, mod = 1e9 + 7;

int n, k;
int a[maxk], s[1 << 11];
char str[maxn];

inline int inc(int x, int y) {
  x += y;
  return x >= mod ? x - mod : x;
}

inline int calc(int x) {
  int res = 0;
  for (int i = k - 1; i >= 0; --i) res = inc(res * x, a[i]);
  // cout << res << '\n';
  return res;
}

inline int main() {
  cin >> str >> k;
  for (int i = 0; i < k; ++i) cin >> a[i];
  int slen = strlen(str);
  if (slen <= 21) {
    std::reverse(str, str + slen);
    for (int i = 0; i < slen; ++i) n |= ((str[i] - '0') << i);
    for (int i = 1; i < n; ++i)
      if (i & 1)
        s[i] = s[i >> 1] ^ 1;
      else
        s[i] = s[i >> 1];
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i]) ans = inc(ans, calc(i));
    }
    cout << ans;
  } else {
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("angry.in", "r", stdin);
  freopen("angry.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
